package com.evan.framework.core.base;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * @Description:
 * @Author liudeguang
 */
public class AbstractModel implements Serializable {

    /**
     * 扩展参数
     */
    private final Map<String, String> extFields = new HashMap<>();

    public Map<String, String> getExtFields() {
        return extFields;
    }

    public void setExtFields(final Map<String, String> extFields) {

        if (extFields == null) {
            throw new IllegalArgumentException("extFields is null");
        }

        for (String key : extFields.keySet()) {
            this.extFields.put(key, extFields.get(key));
        }
    }

    public void copyExtFields(final Map<String, String> extFields) {
        this.setExtFields(extFields);
    }

    public void removeExtField(String key) {
        if (key == null || key.trim().equals("")) {
            throw new IllegalArgumentException("Key is null");
        }

        this.extFields.remove(key);
    }

    public String getExtField(String key) {
        if (key == null || key.trim().equals("")) {
            throw new IllegalArgumentException("Key is null");
        }

        return this.extFields.get(key);
    }


    public void putExtField(String key, String value) {
        if (key == null || key.trim().equals("")) {
            throw new IllegalArgumentException("Key is null");
        }

        if (value == null || value.trim().equals("")) {
            throw new IllegalArgumentException("Value is null");
        }

        this.extFields.put(key, value);
    }


}
